import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import router from './router'
import store from './store'
import storage from './utils/storage'
import request from './utils/request'
import api from './api'
import App from './App.vue'

console.log("环境变量=>",import.meta.env)

const app = createApp(App)

app.directive('has', {
  beforeMount: function(el, binging) {
    let acitonList = storage.getItem('actionList')
    let value = binging.value
    let hasPermission = acitonList.includes(value)
    if(!hasPermission) {
      el.style = 'display:none'
      setTimeout(() => {
        el.parentNode.removeChild(el)
      }, 0);
    }
  }
})

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.config.globalProperties.$request = request
app.config.globalProperties.$storage = storage
app.config.globalProperties.$api = api
// // vue3.0 要使用全局变量，需要使用provide inject 这两个函数
// app.provide('$request', request)
// app.provide('$storage', storage)
// app.provide('$api', api)
app.use(router).use(store).use(ElementPlus).mount('#app')
